#pragma once
/*
* 1: friend struct Singleton<MySingleton>;
* 2: private constructor
struct MySingleton : public Singleton<MySingleton> {
private:
    friend class Singleton<MySingleton>;
    MySingleton() = default;
};
*/

template <typename T> struct Singleton {
  static T *get() {
    if (!instance) {
      instance = new T();
    }
    return instance;
  }

protected:
  static T *instance;
  Singleton() {}
  virtual ~Singleton() {}
};

template <typename T> T *Singleton<T>::instance = nullptr;
